package alg20250207;

public class Text {
    public boolean isHappy(int n) {
        int slow = fun(n), fast = fun(fun(n));
        while(slow != fast){
            slow = fun(slow);
            fast = fun(fun(fast));
        }
        return slow == 1 ? true : false;
    }

    public int fun(int n){
        int sum = 0;
        while(n > 0){
            sum += (n % 10) * (n % 10);
            n /= 10;
        }
        return sum;
    }
}
